/*
 * @Author: taoyuqing
 * @Date: 2023-02-22 00:51:41
 * @Description: 
 */
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:spree/utils/utils.dart';
import 'package:spree/widgets/common_container.dart';
import 'package:spree/widgets/vip_rectangle_box.dart';

import '../../utils/precision_limit_formatter.dart';

class FaitPage extends StatefulWidget {
  FaitPage({Key? key}) : super(key: key);

  @override
  State<FaitPage> createState() => _FaitPageState();
}

class _FaitPageState extends State<FaitPage> {
  List _depositAmounts = [
    {'number': 20, 'isSelect': false},
    {'number': 50, 'isSelect': false},
    {'number': 100, 'isSelect': false},
    {'number': 150, 'isSelect': false},
    {'number': 250, 'isSelect': false},
    {'number': 500, 'isSelect': false}
  ];
  late TextEditingController _textEditingController;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _textEditingController = TextEditingController(text: '');
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('fait'),
      ),
      body: CommonContainer(
        child: ListView(
          children: [
            Container(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Container(
                      margin: EdgeInsets.only(top: 10),
                      child: Row(
                        children: [
                          Text(
                            'Currency:',
                            style: TextStyle(
                                color: Colors.white,
                                fontSize: 14,
                                fontWeight: FontWeight.w700),
                          ),
                          VipRectangleBox(
                            margin: EdgeInsets.only(left: 20),
                            padding: EdgeInsets.only(
                                left: 10, right: 10, top: 5, bottom: 5),
                            color: Color(0xFF29205F),
                            child: Text(
                              'TRC20',
                              style: TextStyle(
                                  color: Color(0xFFFFED4A),
                                  fontWeight: FontWeight.w700),
                            ),
                          ),
                          VipRectangleBox(
                            margin: EdgeInsets.only(left: 20),
                            padding: EdgeInsets.only(
                                left: 10, right: 10, top: 5, bottom: 5),
                            color: Color(0xFF29205F),
                            child: Text(
                              'PIX',
                              style: TextStyle(
                                  color: Color(0xFFFFED4A),
                                  fontWeight: FontWeight.w700),
                            ),
                          ),
                          VipRectangleBox(
                            margin: EdgeInsets.only(left: 20),
                            padding: EdgeInsets.only(
                                left: 10, right: 10, top: 5, bottom: 5),
                            color: Color(0xFF29205F),
                            child: Text(
                              'PICPAY',
                              style: TextStyle(
                                  color: Color(0xFFFFED4A),
                                  fontWeight: FontWeight.w700),
                            ),
                          ),
                        ],
                      )),
                  VipRectangleBox(
                    margin: EdgeInsets.only(top: 20),
                    alignment: Alignment.centerLeft,
                    height: 50,
                    color: Color(0xFF29205F),
                    child: Row(
                      children: [
                        Text(
                          'R\$  ',
                          style: TextStyle(
                              color: Color(0xFFFFED4A),
                              fontWeight: FontWeight.w800),
                        ),
                        Text(
                          'BRL',
                          style: TextStyle(
                              color: Colors.white, fontWeight: FontWeight.w800),
                        )
                      ],
                    ),
                  ),
                  Padding(
                    padding: EdgeInsets.only(top: 20),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          'Money:',
                          style: TextStyle(
                              color: Colors.white,
                              fontSize: 14,
                              fontWeight: FontWeight.w700),
                        ),
                        VipRectangleBox(
                          margin: EdgeInsets.only(top: 20),
                          alignment: Alignment.centerLeft,
                          height: 50,
                          color: Color(0xFF29205F),
                          child: Row(
                            children: [
                              Text(
                                'R\$  ',
                                style: TextStyle(
                                    color: Color(0xFFFFED4A),
                                    fontWeight: FontWeight.w800),
                              ),
                              Expanded(
                                  child: Container(
                                child: TextField(
                                    controller: _textEditingController,
                                    keyboardType: TextInputType.number,
                                    inputFormatters: [
                                      // FilteringTextInputFormatter.allow(
                                      //     RegExp("[0-9]"))
                                      PrecisionLimitFormatter(2)
                                    ],
                                    cursorColor: Colors.white,
                                    style: TextStyle(color: Colors.white),
                                    decoration: InputDecoration(
                                      border: InputBorder.none,
                                    )),
                              ))
                            ],
                          ),
                        )
                      ],
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.only(top: 20),
                    child: Wrap(
                      spacing: 10,
                      runSpacing: 10,
                      children: _depositAmount(_depositAmounts, (data) {
                        _textEditingController.text = '${data['number']}';
                      }),
                    ),
                  ),
                  Container(
                    width: Utils().getScreenWidth(context),
                    height: 40,
                    margin: EdgeInsets.only(top: 10),
                    child: ElevatedButton(
                        style: ButtonStyle(
                          backgroundColor:
                              MaterialStateProperty.all(Color(0xFF685BB1)),
                        ),
                        onPressed: () {},
                        child: Text('Buy')),
                  )
                ],
              ),
            )
          ],
        ),
      ),
    );
  }

  List<Widget> _depositAmount(List list, Function onTap) {
    return list.map((e) {
      return VipRectangleBox(
        onTap: () {
          setState(() {
            for (var element in list) {
              element['isSelect'] = false;
            }
            e['isSelect'] = true;
          });
          onTap(e);
        },
        width: 100,
        padding: EdgeInsets.only(top: 5, bottom: 6),
        color: e['isSelect'] ? Color(0xFF685BB1) : Color(0xFF29205F),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text('R\$  ',
                style: TextStyle(
                    color: Colors.white, fontWeight: FontWeight.w800)),
            Text('${e['number']}',
                style: TextStyle(
                  color: Colors.white,
                ))
          ],
        ),
      );
    }).toList();
  }
}
